package wheel;

import java.sql.Connection;
import java.sql.DriverManager;

public class JDBCMySQLConnection {

	/* Using the Singleton pattern, create a unique instance of
	   JDBCMySQLConnection.  Since we always need a database connection,
	   create the JDBCMySQLConnection instance eagerly.
	*/
	private static JDBCMySQLConnection uniqueInstance = new JDBCMySQLConnection();
	public static final String URL = "jdbc:mysql://localhost/wordnet30";
	public static final String USER = "root";
	public static final String PASSWORD = "rrrr";
    public static final String DRIVER_CLASS = "com.mysql.jdbc.Driver"; 
	 
    //private constructor
    private JDBCMySQLConnection() {
        try {
            //Step 2: Load MySQL Java driver
            Class.forName(DRIVER_CLASS);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
	 
	    private Connection createConnection() {
	 
	        Connection connection = null;
	        try {
	            //Step 3: Establish Java MySQL connection
	            connection = DriverManager.getConnection(URL, USER, PASSWORD);
	        } catch (Exception e) {
	            System.out.println("ERROR: Unable to Connect to Database.");
	            e.printStackTrace();
	        }
	        return connection;
	    }   
	 
	    public static Connection getConnection() {
	        return uniqueInstance.createConnection();
	    }

}
